package com.formation.tocea.library.client.ui.form;

import com.formation.tocea.library.client.listener.AddBookListener;
import com.formation.tocea.library.client.listener.HideFormListener;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.ListBox;

public class AddBookForm extends Grid {
	private Label bookTitleLabel;
	private Label bookISBNLabel;
	private Label bookAuthorLabel;
	private Label bookGenreLabel;
	private Label bookEditionDateLabel;
	private Label bookCopiesLabel;
	private TextBox bookTitleTextBox;
	private TextBox bookISBNTextBox;
	private ListBox bookAuthorListBox;
	private TextBox bookGenreTextBox;
	private TextBox bookEditionDateTextBox;
	private TextBox bookCopiesTextBox;
	private HorizontalPanel buttonPanel;
	private Button submitButton;
	private Button closeButton;

	public AddBookForm() {
		init();
	}

	public void init() {
		setWidth("100");
		resize(7, 2);
		
		bookTitleLabel = new Label("Titre");
		bookISBNLabel = new Label("ISBN");
		bookAuthorLabel = new Label("Author");
		bookGenreLabel = new Label("Genre");
		bookEditionDateLabel = new Label("Date édition");
		bookCopiesLabel = new Label("Copies");
		
		bookTitleTextBox = new TextBox();
		bookISBNTextBox = new TextBox();
		bookAuthorListBox = new ListBox(false);
		bookGenreTextBox = new TextBox();
		bookEditionDateTextBox = new TextBox();
		bookCopiesTextBox = new TextBox();
		
		buttonPanel = new HorizontalPanel();
		submitButton = new Button("Ajouter");
		closeButton = new Button("Annuler");
		buttonPanel.add(submitButton);
		buttonPanel.add(closeButton);
		
		bookAuthorListBox.setWidth("100%");
		submitButton.addClickHandler(new AddBookListener());
		closeButton.addClickHandler(new HideFormListener(this));

		setWidget(0, 0, bookTitleLabel);
		setWidget(0, 1, bookTitleTextBox);
		setWidget(1, 0, bookISBNLabel);
		setWidget(1, 1, bookISBNTextBox);
		setWidget(2, 0, bookAuthorLabel);
		setWidget(2, 1, bookAuthorListBox);
		setWidget(3, 0, bookGenreLabel);
		setWidget(3, 1, bookGenreTextBox);
		setWidget(4, 0, bookEditionDateLabel);
		setWidget(4, 1, bookEditionDateTextBox);
		setWidget(5, 0, bookCopiesLabel);
		setWidget(5, 1, bookCopiesTextBox);
		setWidget(6, 1, buttonPanel);
	}
}
